<?php

//apd_set_pprof_trace();
require_once('../includes/DB.class.php');
require_once('../includes/SmartyManager.class.php');
require_once('../includes/exceptions/AppExceptions.class.php');
require_once('../includes/SimpleTableExporter.class.php');

$filename = '总表二剩余_'.date('YmdHis').'.xls';

ini_set("max_execution_time",0);
ini_set( "memory_limit" , "128M");

try{
	$exp = new SimpleTableExporter($filename);
	$query = "select * from little_main2 where remainCount > 0;";
	$certificationNumber = array();
	$count = array();
	$remainCount = array();
	$orderNumber = array();
	$orderSubitemNumber = array();
	$sampleBatch = array();

	DB::query($query);
	$result = DB::getResult();
	while($row = $result->fetch_assoc()){
			array_push($certificationNumber, $row['certificationNumber']);
			array_push($count, $row['count']);
			array_push($remainCount, $row['remainCount']);		
			array_push($orderNumber, $row['orderNumber']);
			array_push($orderSubitemNumber, $row['orderSubitemNumber']);
			array_push($sampleBatch,$row['sampleBatch']);
	}

	$exp->insertCustomData(array($certificationNumber,$count,$remainCount,$orderNumber,$orderSubitemNumber,$sampleBatch), 
							array('产品质量证明书号','数量','剩余数量','订单号','订单子项号','批号'), 'sheet1');
	$exp->export();
	
}catch(Exception $e){
	$smarty = SmartyManager::getSmarty();
	$smarty->assign('errMsg', $e);
	$smarty->assign('errTitle', '查询数据库时出现错误');
	$smarty->display('error.html');
	die();
}
?>

